using Dapper.Extensions.Configuration;
using Dapper.Extensions.Retry;
using Microsoft.Extensions.DependencyInjection;

namespace Dapper.Extensions;

public class DapperBuilder
{
	private readonly IServiceCollection _services;
	
	internal DapperBuilder(IServiceCollection services)
	{
		_services = services;
	}
	
	public DapperOptions Options { get; } = new();

	public DapperBuilder EnabledRetry(Action<RetryOptions>? configure = null)
	{
		Options.EnabledRetry = true;
		if (configure != null)
		{
			var options = new RetryOptions();
			configure(options);
			Options.Retry = options;
		}
		return this;
	}

	public DapperBuilder EnableLogging(Action<DbLoggingConfigurationBuilder>? configure = null)
	{
		Options.EnableLogging = true;
		if (configure != null)
		{
			var builder = new DbLoggingConfigurationBuilder();
			configure(builder);
			Options.LoggingConfiguration = builder.Build();
		}
		return this;
	}
}
